package com.neutech.shop.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.math.BigDecimal;
import java.sql.Timestamp;

/**
 * @author Neuedu-远哥
 * @version 1.0
 * @date 2021/9/29 9:23
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Product implements Serializable {

    private Long id;
    private String name;
    private String descr;
    private Double normalPrice;
    private Double memberPrice;

    private String imgPath;
    private Integer categoryId;
    private Category category;
    private Timestamp createTime;
    private Timestamp updateTime;

    public Product(String name, String descr, Double normalPrice, Double memberPrice, String imgPath, Category category) {
        this.name = name;
        this.descr = descr;
        this.normalPrice = normalPrice;
        this.memberPrice = memberPrice;
        this.imgPath = imgPath;
        this.category = category;
    }

    /**
     * 会员价格是普通价格的8折
     * @param name
     * @param descr
     * @param normalPrice
     * @param imgPath
     * @param category
     */
    public Product(String name, String descr, Double normalPrice, String imgPath, Category category) {
        this.name = name;
        this.descr = descr;
        this.normalPrice = Math.round(normalPrice * 100.0)/100.0;
        this.imgPath = imgPath;
        this.category = category;
        this.memberPrice = Math.round(this.normalPrice * 0.8 * 100.0) / 100.0;
    }
}
